package com.zabra.zl.ui.clear;

import android.app.Dialog;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jwenfeng.library.pulltorefresh.PullToRefreshLayout;
import com.zabra.zl.Config;
import com.zabra.zl.R;
import com.zabra.zl.base.BaseMvpActivity;
import com.zabra.zl.data.ClearBean;
import com.zabra.zl.myview.state_layout.OtherView;
import com.zabra.zl.ui.clear.contract.ClearContract;
import com.zabra.zl.ui.clear.presenter.ClearPresenter;
import com.zabra.zl.utils.DialogUtils;
import com.zabra.zl.utils.ShowDialogUtils;
import com.zabra.zl.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ClearActivity extends BaseMvpActivity<ClearPresenter> implements ClearContract.View {


    @BindView(R.id.back)
    LinearLayout back;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.recycler)
    RecyclerView recycler;
    @BindView(R.id.otherview)
    OtherView otherview;
    private List<ClearBean.RespDataBean> list;
    private Adp adp;
    private int orderId;
    private Dialog dialog;

    @Override
    public int getLayoutId() {
        return R.layout.activity_clear;
    }

    @Override
    public void initView() {
        tvTitle.setText("已清仓查询");
        orderId = getIntent().getExtras().getInt("orderid");
        otherview.setHolder(mHolder);
        mPresenter = new ClearPresenter();
        mPresenter.attachView(this);
        mPresenter.getData(orderId);


    }

    @Override
    public void showLoading() {
        dialog = DialogUtils.showDialog_progressbar(this);
    }

    @Override
    public void hideLoading() {
        DialogUtils.closeDialog(dialog);
    }

    @Override
    public void onError(Throwable throwable) {
        DialogUtils.closeDialog(dialog);
    }

    @Override
    public void onSuccess(ClearBean bean) {
            if (bean.getRespCode().equals(Config.SUCCESS)){
                list=bean.getRespData();
                if (list.size()==0){
                    otherview.showEmptyView();
                }else {
                    otherview.showContentView();
                    recycler.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
                    recycler.setNestedScrollingEnabled(false);
                    adp = new Adp(R.layout.item_clear, list);
                    recycler.setAdapter(adp);
                    adp.openLoadAnimation();
                }
            }else if (bean.getRespCode().equals(Config.TOKENOUT)){
                ShowDialogUtils.restLoginDialog(this);
            }else {
                ToastUtil.showToast(this,bean.getRespDesc());
            }
    }

    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }
}
